<?php
namespace App\Http\Controllers\Api;
use App\Events\FlowChangeEvent;
use App\Helpers\Api\MiniProgramTrait;
use App\Lib\QiNiuAdapter;
use App\Listeners\PushTemplateListener;
use App\Models\Car;
use App\Models\Config;
use Dingo\Api\Http\Request;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Storage;

class TestController extends BaseController {
    use MiniProgramTrait;

    public function init(Request $request) {
        \Log::info('----test init------');
        $car = new Car();
        $car->find(15619);
        \Log::info('----test end------');
        return ;
        $app = $this->miniProgram();
        $list = $app->subscribe_message->getTemplates();
        dd($list);

        $aa = Config::isShowLoad();
        return $aa;
        exit;
//        opcache_reset();
//        $cache_key_date = 'cache_key_appoint_' . $request->input('date', date('Y-m-d'));
//        $value = $request->input('value', 0);
//        Redis::set($cache_key_date, $value);
//        $aa = Redis::ttl($cache_key_date);
//        dd($aa);
//        Redis::expire($cache_key_date, 5);
    }


    public function qiniu() {
//        event(new FlowChangeEvent(3088));
//        exit;
//        $data = [
//            'template_id' => 'kBx93EWLkEa7z_LlaEdXemFilhlBISGgSXA810MnKoE', // 所需下发的订阅模板id
//            'touser' => 'oFV2n5Fj8DSDNRUeZOmcaMsZVDOI',     // 接收者（用户）的 openid
//            'page' => '',       // 点击模板卡片后的跳转页面，仅限本小程序内的页面。支持带参数,（示例index?foo=bar）。该字段不填则模板无跳转。
//            'data' => [         // 模板内容，格式形如 { "key1": { "value": any }, "key2": { "value": any } }
//                'name1' => [
//                    'value' => '张三',
//                ],
//                'thing2' => [
//                    'value' => '办公室',
//                ],
//                'date3' => [
//                    'value' => '2019/10/14'
//                ]
//            ],
//        ];

        $app = $this->miniProgram();
        $list = $app->subscribe_message->getTemplates();
        dd($list);

//        echo (new QiNiuAdapter())->getToken();exit;
        try{
            $filename = date('YmdHis'). rand(0, 100000) . ".mp4";
//            Storage::disk('qiniu')->write($filename, public_path('logo/20200501/1588301635_5eab8f433f002.jpg'));
            $result = Storage::disk('qiniu')->write($filename, public_path('aaa.mp4'));

        }catch (\Exception $e) {
            dd($e->getMessage());
        }
    }
}
